package com.zxc.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;


import com.zxc.util.DBUtil;

public class ReceiveDataDAO extends BaseDAO {
	public int insertData(DBUtil toDBUtil,List<Object[]> list, String sql) throws SQLException {
		Connection con = null;
		PreparedStatement ps = null;
		try {
			con = toDBUtil.getConnection();
			ps = con.prepareStatement(sql);
			for(Object[] temp : list){
				for(int i = 0 ; i < temp.length; i++){
					ps.setObject(i+1, temp[i]);
				}
				ps.addBatch();
			}
			int nums[] = ps.executeBatch();
			con.commit();
			return nums.length;
		} catch (SQLException e) {
			con.rollback();
			throw e;
		} finally{
			releaseResource(con, ps, null);
		}
	}
}
